package com.maotai.thread;

import android.app.AlertDialog;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alipay.android.zoloz.R;
import com.alipay.mobile.security.zim.api.ZIMFacade;
import com.maotai.bean.MaotaiAppCookie;
import com.maotai.dao.QiangGouDao;
import com.maotai.util.IPFactory;
import com.maotai.util.MaotaiAppHttpClientUtil;

import android.content.Context;

import org.apache.http.client.config.RequestConfig;

import java.io.IOException;
import java.net.URLEncoder;
import java.util.List;
import java.util.Map;

import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

public class MyThread extends Thread {
    private Context context;
    public MyThread(Context context){
        this.context = context;
    }
    @Override
    public void run(){
        QiangGouDao qgdao = new QiangGouDao();
        List<Map<String,Object>> list = qgdao.getAllZhanghaoLoginAndBuy2018();
        if(list!=null && list.size()>0) {
            Map<String, Object> zhanghao = list.get(0);
            String code =  zhanghao.get("code") + "-------------";
            String auth = zhanghao.get("auth")+"";
            String memberId = zhanghao.get("memberId")+"";
            MaotaiAppCookie maotaiAppCookie = new MaotaiAppCookie();
            maotaiAppCookie.setAuth(auth);
            maotaiAppCookie.setMemberid(memberId);
            //获得metainfo
            String metaInfos = ZIMFacade.getMetaInfos(context);
            //将metainfo传到茅台服务端，得到 "zimId" : "e1570236d1cee15043f1823e202d628b",
            String initUrl = "https://i.cmaotai.com/huieryun-identity/api/v1/authant/faceverify/init?mtBizId=2&metainfo="+ URLEncoder.encode("metaInfos");




            MaotaiAppHttpClientUtil maoHttp = MaotaiAppHttpClientUtil.getInstance();
            JSONArray jArray = IPFactory.getIpAndPort();
            JSONObject jj = jArray.getJSONObject(0);
            RequestConfig config = IPFactory.getKdRequestConfig(jj.getString("ip")+":"+jj.getString("port"));
            maotaiAppCookie = maoHttp.sendHttpGetProxy(initUrl,maotaiAppCookie,config,null);
            // "bizId" : "EMAOTAI_20180814093735856536",

            //然后发起认证，认证完了回传到茅台服务器
            //最后提交预约信息
            System.out.println(code);
        }
    }
}
